package com.zkjl.protect_business.config;


import com.zkjl.protect_business.common.Status;
import com.zkjl.protect_business.utils.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.web.access.AccessDeniedHandler;


/**
 * <p>
 * Security 结果处理配置
 * </p>
 */
@Configuration
@Slf4j
public class SecurityHandlerConfig {

    @Bean
    public AccessDeniedHandler accessDeniedHandler() {
        return (request, response, accessDeniedException) -> {
            log.error("权限错误",accessDeniedException);
            String origin = request.getHeader("Origin");
            ResponseUtil.renderJson(response, origin, Status.ACCESS_DENIED, null);
        };
    }

}
